/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.gastronomico.demo.web;

import com.gastronomico.demo.domain.TipoComida;
import com.gastronomico.demo.domain.Ubigeo;
import com.gastronomico.demo.service.TipoComidaService;
import com.gastronomico.demo.service.UbigeoService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.asm.commons.Method;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author MIGUELANGEL
 */
@Controller
public class UbigeoController {

    @Autowired
    UbigeoService service;

    @RequestMapping(value = "/departamentoLista.htm", method = RequestMethod.GET)
    public ModelAndView departamento(){
        ModelAndView mav = new ModelAndView("departamentoLista");
        List<Ubigeo> ubigeoLista = service.obtenerDepartamentos();
        System.out.println("DEPARTAMENTOS:" + ubigeoLista.size());
        mav.addObject("ubigeoLista", ubigeoLista);
        return mav;
    }

    @RequestMapping(value = "/provinciaLista.htm",  method = RequestMethod.GET)
    public ModelAndView provincia(HttpServletRequest req){
        ModelAndView mav = new ModelAndView("provinciaLista");

        String dept = req.getParameter("dept");
        List<Ubigeo> ubigeoLista = service.obtenerProvincias(dept);
        System.out.println("PROVINCIAS:" + ubigeoLista.size());
        mav.addObject("ubigeoLista", ubigeoLista);
        return mav;
    }

    @RequestMapping(value = "/distritoLista.htm", method = RequestMethod.GET)
    public ModelAndView distrito(HttpServletRequest req){
        ModelAndView mav = new ModelAndView("distritoLista");
        String dept = req.getParameter("dept");
        String prov = req.getParameter("prov");
        List<Ubigeo> ubigeoLista = service.obtenerDistritos(dept, prov);
        System.out.println("DISTRITOS:" + ubigeoLista.size());
        mav.addObject("ubigeoLista", ubigeoLista);
        return mav;
    }

}
